package auctionhaus


import org.junit.*
import grails.test.mixin.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Bid)
class BidTests {

	Bid bid;

	@Before
	void setUp() {

		bid = new Bid()
	}

	@After
	void tearDown() {
		// Tear down logic here
	}

	//B-1: Bids have the following required fields: amount and date/time of bid (unit test)
	void testFieldsExist(){
		assertFalse(bid.validate(['amount']));
		assertTrue(bid.validate(['dateCreated']));
		
		bid.listing = new Listing(startingPrice: 10.00 )
		bid.amount = 12.00

		assertTrue(bid.validate(['amount']));
		assertTrue(bid.validate(['dateCreated']));
	}
	//B-2: Bids are required to be for a Listing (unit test)
	void testListingRequired(){
		assertNull(bid.listing)
		assertFalse(bid.validate(['listing']))

		bid.listing= new Listing();
		assertNotNull(bid.listing)
		assertTrue(bid.validate(['listing']))
	}
	//B-3: Bids are required to have a bidder (Customer) (unit test)
	void testBidderRequired(){
		assertNull(bid.bidder)
		assertFalse(bid.validate(['bidder']))

		bid.bidder = new Customer();
		assertNotNull(bid.bidder)
		assertTrue(bid.validate(['bidder']))
	}
	//B-4: A Listing has a list of Bids for that Listing (unit test)
	void testRequiredBidsList()
	{
		mockDomain(Listing)
		Listing listing = new Listing();

		Bid b = new Bid(amount: 10.00);
		listing.addToBids(b);

		assertNotNull(listing.bids)
		assertTrue(listing.validate(['bids']));
	}
}
